package com.zzc.emotisenseclassroom.dbservice.EmotisenseScore.impl;

import com.github.pagehelper.PageHelper;
import com.zzc.baseRepository.componet.interfaces.BaseDbService;
import com.zzc.emotisenseclassroom.dao.EmotisenseScore.EmotisenseScoreDao;
import com.zzc.emotisenseclassroom.dbservice.EmotisenseScore.EmotisenseScoreDbService;
import com.zzc.emotisenseclassroom.domain.classScore.vo.EmotiSenseScoreVO;
import com.zzc.emotisenseclassroom.dto.emotisenseScore.EmotisenseScoreDTO;
import com.zzc.emotisenseclassroom.utils.ConstantUtil;
import com.zzc.utils.Verify;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * Copyright Zzc
 * FileName: EmotisenseScoreDbServiceImpl
 * Author:   Zzc
 * Date:     2024/5/323:08
 * Description:
 * hISTORY:
 * <author>  <time>     <version>    <desc>
 * 作者姓名   修改时间       版本号       描述
 * Zzc                   1.0.0
 */
@Service
public class EmotisenseScoreDbServiceImpl extends BaseDbService<EmotisenseScoreDao> implements EmotisenseScoreDbService {
    @Override
    public List<EmotiSenseScoreVO> getClassEmotisenseScore(Date dateBegin, Date dateEnd, Long schoolId, Long classId) {
        if (dateBegin == null || dateEnd == null || schoolId == null || classId == null || dateBegin.compareTo(dateEnd)>=0){
            return Collections.emptyList();
        }

        List<EmotiSenseScoreVO> resultList = new ArrayList<>();
        int pageNum = 1;
        while (true) {
            PageHelper.startPage(pageNum++, ConstantUtil.LIST_SIZE);
            List<EmotiSenseScoreVO> tempList = baseDao.getClassEmotisenseScore(dateBegin, dateEnd, schoolId, classId);

            if (!Verify.isEmpty(tempList)) {
                resultList.addAll(tempList);
            }

            if (Verify.isEmpty(tempList) || tempList.size() < ConstantUtil.LIST_SIZE) {
                break;
            }
        }

        return resultList;
    }

    @Override
    public List<EmotiSenseScoreVO> getStudentEmotisenseScore(Date dateBegin, Date dateEnd, Long schoolId, Long classId, Long userId) {
        if (dateBegin == null || dateEnd == null || schoolId == null || classId == null || userId == null || dateBegin.compareTo(dateEnd)>=0){
            return Collections.emptyList();
        }

        List<EmotiSenseScoreVO> resultList = new ArrayList<>();
        int pageNum = 1;
        while (true) {
            PageHelper.startPage(pageNum++, ConstantUtil.LIST_SIZE);
            List<EmotiSenseScoreVO> tempList = baseDao.getStudentEmotisenseScore(dateBegin, dateEnd, schoolId, classId, userId);

            if (!Verify.isEmpty(tempList)) {
                resultList.addAll(tempList);
            }

            if (Verify.isEmpty(tempList) || tempList.size() < ConstantUtil.LIST_SIZE) {
                break;
            }
        }

        return resultList;
    }

    @Override
    public void insertScore(List<EmotisenseScoreDTO> scoreList) {
        if (Verify.isEmpty(scoreList)){
            return;
        }

        baseDao.insertScore(scoreList);
    }
}
